cmake_minimum_required(VERSION 3.5)
project(turtle_bt_ros2)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Widgets)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(behaviortree_cpp_v3 REQUIRED)

find_package(Boost COMPONENTS coroutine QUIET) # 行为树所需
find_package(Threads) # 行为树所需
find_package(Curses QUIET) # 行为树所需

list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES
  ${CMAKE_THREAD_LIBS_INIT}
  ${CMAKE_DL_LIBS}
  ${Boost_LIBRARIES}
  ${Curses_LIBRARIES}
) # 行为树所需

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
include_directories(
  include
  ${Qt5Widgets_INCLUDE_DIRS}
  /home/ros/ws/install/turtle_bt_ros2/include
)

# include_directories(/opt/ros/dashing/include/tf2/LinearMath/)
include_directories(/home/ros/ws/src/turtle_bt_ros2/nodes)

# include_directories(${CMAKE_SOURCE_DIR}/include) # 行为树所需
# include_directories(${CMAKE_SOURCE_DIR}/sample_nodes) # 行为树所需
# find_library(BT_LIB behaviortree_cpp_v3 HINTS ${CMAKE_SOURCE_DIR}/lib)
rosidl_generate_interfaces(${PROJECT_NAME}
  "action/RotateAbsolute.action"
  "msg/Color.msg"
  "msg/Pose.msg"
  "srv/Kill.srv"
  "srv/SetPen.srv"
  "srv/Spawn.srv"
  "srv/TeleportAbsolute.srv"
  "srv/TeleportRelative.srv"
  "action/BT.action"
)

set(dependencies
  "ament_index_cpp"
  "geometry_msgs"
  "rclcpp"
  "rclcpp_action"
  "std_msgs"
  "std_srvs"
  "turtle_tf2_listener_timeout"
  "behaviortree_cpp_v3"
  "tf2"
  "tf2_ros"
)


set(turtle_bt_ros2_node_SRCS
  src/bt_turtle_demo.cpp
  src/turtle.cpp
  src/turtle_frame.cpp
)
set(turtle_bt_ros2_node_HDRS
  include/turtle/turtle_frame.h
)

qt5_wrap_cpp(turtle_bt_ros2_node_MOCS ${turtle_bt_ros2_node_HDRS})

add_executable(turtle_bt_ros2_node ${turtle_bt_ros2_node_SRCS} ${turtle_bt_ros2_node_MOCS})
target_link_libraries(turtle_bt_ros2_node Qt5::Widgets)
ament_target_dependencies(turtle_bt_ros2_node ${dependencies})
rosidl_target_interfaces(turtle_bt_ros2_node ${PROJECT_NAME} "rosidl_typesupport_cpp")
add_executable(turtle_teleop_key tutorials/teleop_turtle_key.cpp)
ament_target_dependencies(turtle_teleop_key ${dependencies})
rosidl_target_interfaces(turtle_teleop_key ${PROJECT_NAME} "rosidl_typesupport_cpp")
add_executable(draw_square tutorials/draw_square.cpp)
ament_target_dependencies(draw_square ${dependencies})
rosidl_target_interfaces(draw_square ${PROJECT_NAME} "rosidl_typesupport_cpp")
add_executable(mimic tutorials/mimic.cpp)
ament_target_dependencies(mimic ${dependencies})
rosidl_target_interfaces(mimic ${PROJECT_NAME} "rosidl_typesupport_cpp")
add_executable(client src/new_turtle2.cpp)
ament_target_dependencies(client ${dependencies})
rosidl_target_interfaces(client ${PROJECT_NAME} "rosidl_typesupport_cpp")
add_executable(myturtle_tf_broadcaster src/myturtle_tf_broadcaster.cpp)
ament_target_dependencies(myturtle_tf_broadcaster ${dependencies})
rosidl_target_interfaces(myturtle_tf_broadcaster ${PROJECT_NAME} "rosidl_typesupport_cpp")
add_executable(npcturtle_tf_broadcaster src/npcturtle_tf_broadcaster.cpp)
ament_target_dependencies(npcturtle_tf_broadcaster ${dependencies})
rosidl_target_interfaces(npcturtle_tf_broadcaster ${PROJECT_NAME} "rosidl_typesupport_cpp")
add_executable(bt_turtle2_tree src/bt_turtle2_tree.cpp)
ament_target_dependencies(bt_turtle2_tree ${dependencies})
target_link_libraries(bt_turtle2_tree
behaviortree_cpp_v3
)

# target_link_libraries(bt_turtle2_tree ${BT_LIB} ${BEHAVIOR_TREE_EXTERNAL_LIBRARIES} )
# rosidl_target_interfaces(bt_turtle2_tree ${PROJECT_NAME} "rosidl_typesupport_cpp")

# add_executable(demo src/demo.cpp)
# ament_target_dependencies(demo ${dependencies})
# rosidl_target_interfaces(demo ${PROJECT_NAME} "rosidl_typesupport_cpp")

install(TARGETS turtle_bt_ros2_node turtle_teleop_key draw_square mimic client myturtle_tf_broadcaster npcturtle_tf_broadcaster bt_turtle2_tree
  DESTINATION lib/${PROJECT_NAME})

install( DIRECTORY bt_xml
  DESTINATION share/${PROJECT_NAME}
)
install(DIRECTORY images
  DESTINATION share/${PROJECT_NAME}
  FILES_MATCHING PATTERN "*.png" PATTERN "*.svg")

install(DIRECTORY launch
  DESTINATION share/${PROJECT_NAME})

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)

  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  # set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  # set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
